package test1To10;

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * 数据表记录包含表索引和数值（int范围的正整数），请对表索引相同的记录进行合并，即将相同索引的数值进行求和运算，输出按照key值升序进行输出
 */
public class Test08 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        Map<Integer,Integer> map = new TreeMap<>();
        while (scanner.hasNext()) {
            for (int i = 0; i < num; i++) {
                int index = scanner.nextInt();
                int value = scanner.nextInt();
                if (map.containsKey(index)) {
                    int v = map.get(index) + value;
                    map.put(index, v);
                } else {
                    map.put(index, value);
                }
            }
            for (Map.Entry<Integer, Integer> integerIntegerEntry : map.entrySet()) {
                System.out.println(integerIntegerEntry.getKey()+" "+integerIntegerEntry.getValue());
            }
        }


    }
}
